package xsdcl;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class EngUtils
{
	private List<String> verbList;
	private List<String> polyList;

	public EngUtils()
	{
		verbList = new ArrayList<String>();
		polyList = new ArrayList<String>();
		LoadVerbs();
		LoadPolys();
	}

	public void LoadVerbs()
	{
		System.out.println("Loading verb list...");
		verbList.clear();
		File verbs = new File("./verbs.txt");

		BufferedReader reader = null;
		try
		{
			reader = new BufferedReader(new FileReader(verbs));
		} catch (FileNotFoundException e1)
		{
			e1.printStackTrace();
		}

		String s;
		try
		{
			while ((s = reader.readLine()) != null)
				verbList.add(s);
		} catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	public void LoadPolys()
	{
		System.out.println("Loading poly list...");
		polyList.clear();
		File verbs = new File("./polys.txt");

		BufferedReader reader = null;
		try
		{
			reader = new BufferedReader(new FileReader(verbs));
		} catch (FileNotFoundException e1)
		{
			e1.printStackTrace();
		}

		String s;
		try
		{
			while ((s = reader.readLine()) != null)
				polyList.add(s);
		} catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	public boolean isVerb(String word)
	{
		return verbList.contains(word.trim());	
	}

	public boolean isPoly(String single, String poly)
	{
		String item = single + " " + poly;
		if (polyList.contains(item.trim()))
			return true;
		String s = poly.replaceAll(single, "");
		if (s.equalsIgnoreCase("s") || s.equalsIgnoreCase("es")
				|| s.equalsIgnoreCase("ies"))
			return true;

		return false;
	}
}
